package cn.gene.timeyan.privateletter.webapi.controller;

import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.PrivateLetter.NoticeMessage;
import cn.gene.timeyan.pojo.PrivateLetter.PrivateLetter;
import cn.gene.timeyan.pojo.ums.vo.UserInfoVo;
import cn.gene.timeyan.privateletter.service.PrivateLetterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/PrivateLetter", produces = "application/json; charset=utf-8")
@Api(tags = "私信公告通知模块")
public class PrivateLetterController {

    @Autowired
    private PrivateLetterService service;

    //demo
    @PostMapping("/demo")
    @ApiOperation("demo")
    @ApiImplicitParams({

    })
    public JsonResult<Void> demo() {

        System.out.println("demo");
        return JsonResult.ok();
    }


    /**
     * 增加私信控制器层
     *
     * @param senderId   发送者id
     * @param receiverId 接受者id
     * @param content    发送内容
     * @return
     */
    @PostMapping("/add-new")
    @ApiOperation("添加私信")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发送者id",name="senderId",example = "1"),
            @ApiImplicitParam(value = "接收者id",name="receiverId",example = "10"),
            @ApiImplicitParam(value = "私信内容",name="content",example = "嘿嘿嘿")
    })
    public JsonResult<Void> addNewPrivateLetter(Long senderId, Long receiverId, String content) {
        int row = service.addPrivateLetter(senderId, receiverId, content);
        return JsonResult.ok();
    }


    /**
     * 新增公告
     **************************************************************************
     * 规定:所有公告的receiverId强制设置为0与通知功能中receiverId为接收者id区分
     *      查询公告时也是只查询receiverId为0的公告与通知功能中receiverId为接收者id区分
     *      不至于有用户id会是0吧
     *      英语捉急 公告通知长得几乎一毛一样 我全部搞完前后端对路径的改一改
     **************************************************************************
     * @param title   公告标题
     * @param content 公告内容
     * @return
     */
    @PostMapping("/add-newNoticeMessage")
    @ApiOperation("新增公告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "公告标题",name="title",example = "重大公告"),
            @ApiImplicitParam(value = "公告",name="content",example = "放假回家辣")
    })
    public JsonResult<Void> addNewNoticeMessage(String title, String content) {
        int row = service.addNoticeMessageService(title, content);
        return JsonResult.ok();
    }

    /**
     * 新增通知
     **************************************************************************
     * 规定:设置接收人id
     **************************************************************************
     * @param receiverId   通知人id
     * @param title   通知标题
     * @param content 通知内容
     * @return
     */
    @PostMapping("/add-NewMessageNotification")
    @ApiOperation("新增通知")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "接收者id",name="receiverId",example = "1"),
            @ApiImplicitParam(value = "公告标题",name="title",example = "通知"),
            @ApiImplicitParam(value = "公告内容",name="content",example = "你号没了")
    })
   public JsonResult<Void> addNewMessageNotification(Long receiverId, String title, String content){
        int row = service.addMessageNotification(receiverId,title,content);
        return JsonResult.ok();
   }

    /**
     * 根据id删除私信
     *
     * @param PrivateLetterId 私信id
     * @return
     */
    @PostMapping("/deleteById")
    @ApiOperation("根据id删除私信")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "私信id",name="PrivateLetterId",example = "1")
    })
    public JsonResult<Void> deleteByPrivateLetterId(Long PrivateLetterId) {
        int row = service.deleteById(PrivateLetterId);
        return JsonResult.ok();
    }

    /**
     * 查询当前给用户发私信的发送者
     *
     * @param receiverId 接收者id
     * @return 一个发送者的list集合
     */
    @GetMapping("/list-sender")
    @ApiOperation("查询当前给用户发私信的发送者")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "接收者id",name="receiverId",example = "3")
    })
    public JsonResult<List<UserInfoVo>> senderList(Long receiverId) {
        System.out.println("****************");
        System.out.println("开始控制层");
        List<UserInfoVo> senderIds = service.getSender(receiverId);
        System.out.println("控制层结束");
        return JsonResult.ok(senderIds);
    }


    /**
     * 获取两人来往私信记录
     * @param senderId  发送者id
     * @param receiverId 接收者id
     *
     * @return 一个私信类的list集合
     */
    @PostMapping("/list-content")
    @ApiOperation("获取两人来往私信记录")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发送者id",name="senderId",example = "1"),
            @ApiImplicitParam(value = "接收者id",name="receiverId",example = "3")
    })
    public JsonResult<List<PrivateLetter>> contentList(Long senderId, Long receiverId) {
        System.out.println("**************");
        System.out.println("开始查询两个人来往私信记录");
        List<PrivateLetter> letters = service.getContent(receiverId, senderId);
        System.out.println("查询完毕");
        return JsonResult.ok(letters);
    }

    /**
     * 获取所有官方通告
     *
     * @return 一个官方通告类的list集合
     */
    @GetMapping("/list-NoticeMessageService")
    @ApiOperation("获取所有官方通告")
    public JsonResult<List<NoticeMessage>> GetAllNoticeMessageService() {
        List<NoticeMessage> lists = service.getAllNoticeMessageService();
        return JsonResult.ok(lists);

    }


    /**
     * 获取所有当前用户的通知
     *@param userId 接收者用户id
     *
     */
    @GetMapping("/list-MessageNotification")
    @ApiOperation("获取所有当前用户的通知")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "接收者用户id",name="userId",example = "1")
    })
    public JsonResult<List<NoticeMessage>> getAllMessageNotificationService(Long userId) {
        List<NoticeMessage> lists = service.getAllMessageNotificationServiceByReceiverId(userId);
        return JsonResult.ok(lists);

    }




}
